package com.wrk._2_数组._02_习题;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class _008_降序输出数组元素 {
    public static void main(String[] args) {
        //创建Scanner对象
        Scanner scanner = new Scanner(System.in);
        //输入学生个数
        System.out.print("请输入学生个数：");
        int NumberStudents = scanner.nextInt();
        //定义二维数组
        String [][] array = new String[NumberStudents][2];
        //输入学生姓名和成绩，存入数组
        for (int i = 0; i < array.length; i++) {
            System.out.print("请输入第"+(i+1)+"一个学生姓名：");
            array[i][0] = scanner.next();
            System.out.print("请输入第"+(i+1)+"一个学生成绩：");
            array[i][1] = scanner.next();
        }
        // 按每行的第二个元素升序排序
        //Arrays.sort(array, Comparator.comparingInt(a -> Integer.parseInt(a[1])));
        // 按每行的第二个元素降序排序
        Arrays.sort(array, (a, b) -> b[1].compareTo(a[1]));
        //输出
        System.out.println(Arrays.deepToString(array));
        scanner.close();
    }
}
